﻿@using System.Web.UI.HtmlControls @{ ViewBag.Title = ViewBag.Title; Layout = "~/Views/Shared/_Layuidomnull.cshtml"; }

<div class="site-text site-block layui-form" id="addEditiconForm" style="width: 80%; margin: 0 auto;">
    <p class="layui-layer-title">@ViewBag.Title</p>
    <input type="hidden" value="@ViewBag.Ksystemset.Sid" id="Sid" />
    <div class="AddiconBox ">
        <table cellSpacing="0" cellPadding="0" class="layui-table" width="80%" border="0">
            <tr>
                <td height="25" width="30%" align="right">
                    <label class=" layui-form-label">类型:</label>
                </td>
                <td height="25" width="*" align="left">
                    <input id="txtStype" runat="server" Width="200px" class="layui-input" readonly value="Icon" />
                </td>
            </tr>
            <tr>
                <td height="25" width="30%" align="right">
                    <label class=" layui-form-label">标题:</label>
                </td>
                <td height="25" width="*" align="left">
                    <input id="txtSname" Width="200px" value="@ViewBag.Ksystemset.Sname" class="layui-input" />
                </td>
            </tr>
            <tr>
                <td height="25" width="30%" align="right">
                    <label class="layui-form-label">超链接:</label>
                </td>
                <td height="25" width="*" align="left">
                    <input id="txtSvalue" runat="server" required Width="200px" value="@ViewBag.Ksystemset.Svalue" class="layui-input">
                </td>
            </tr>
            <tr>
                <td height="25" width="30%" align="right">
                    <label class="layui-form-label">icon图片链接:</label>
                </td>
                <td height="25" width="*" align="left">
                    <img src="@ViewBag.Ksystemset.Skey1" width="91" id="Thumimg">
                    <input id="file1" type="file" name="file1" width="200" class="layui-upload-file">
                    <input type="hidden" id="txtSkey1" value="@ViewBag.Ksystemset.Skey1" name="txtSkey1" />
                </td>
            </tr>
            <tr>
                <td height="25" width="30%" align="right">
                    <label class="layui-form-label">请选择窗口</label>
                </td>
                <td>
                    <select name="windowtitle" id="windowtitle" lay-verify="" title="自定义填写作为新窗口添加" lay-search>
                        <option></option>
                        @Html.Raw(@ViewBag.WindowTitle)
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="text-center" align="center"><input type="button" id="SubmitIcon" class="btn-default layui-btn" value="提交" /></td>
            </tr>
        </table>

    </div>
</div>
<script src="~/Content/layui/lay/modules/form.js"></script>
<script>
    $(function () {
        $("#SubmitIcon").bind("click",
            function () {
                var Sid = $("#Sid").val();
                $.post("/SystemSet/AddHomeIconAction?Sid=" + Sid, {
                    txtStype: $("#txtStype").val(),
                    txtSname: $("#txtSname").val(),
                    txtSvalue: $("#txtSvalue").val(),
                    txtSkey1: $("#txtSkey1").val(),
                    windowtitle: $(".layui-unselect input").val()
                },
                    function (data) {
                        data = $.parseJSON(data);
                        if (Sid < 1) {
                            //添加icon操作
                            if (data.result > 0) {
                                var index = parent.layer.getFrameIndex(window.name);
                                layer.msg("添加成功");
                                parent.layer.close(index);
                                parent.window.location.reload();
                            } else {
                                layer.alert("<p style='color:red'>添加失败<p><br>请检查填写文案");
                            }
                        }
                        else {
                            //修改icon操作
                            console.log(data);
                            if (data.result > 0) {
                                var index = parent.layer.getFrameIndex(window.name);
                                layer.msg("修改成功");
                                parent.layer.close(index);
                                parent.window.location.reload();
                                
                            } else {
                                layer.alert("<p style='color:red'>修改失败<p><br>" + data.msg);
                            }
                        }

                    }
                );
            });
        //上传图
        layui.upload({
            url: '/public/Uploadicon',
            success: function (res) {
                // $("#txtSkey1").val(res.pic);
                console.log(document.querySelector("#txtSkey1").value); //上传成功返回值，必须为json格式
                document.querySelector("#txtSkey1").value = res.src;
                $("#Thumimg").attr("src", res.src);
            }
        });
    });
</script>